package com.xjtu.chapter08.thread;

import java.io.IOException;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/30 10:15
 */
class Interrupt extends Thread {
    @Override
    public void run() {
        try {
            sleep(30000);
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
    }
}

public class InterruptTest2 {
    public static void main(String[] args) throws IOException {
        Thread thread = new Interrupt();
        thread.start();
        System.out.println("请在30s内按任意键中断线程");
        System.in.read();//获取输入
        thread.interrupt();
        System.out.println("线程退出");
    }
}
